package cn.controller;

import cn.pojo.Admin;
import cn.pojo.Customer;
import cn.service.AdminService;
import cn.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author jia
 * @Description
 * @date 2019-03-20-19:58
 */
@Controller
@RequestMapping("")
public class AdminController {
    @Autowired
    AdminService adminService;
    @Autowired
    CustomerService customerService;

    @RequestMapping("")
    public String login() {
        return "admin/login";
    }

    @RequestMapping("admin_login")
    public String adminLogin() {
        return "admin/login";
    }

    @RequestMapping("login")
    public String adminLogin(@RequestParam("name") String name
            , @RequestParam("password") String password
            , Model model, HttpSession session) {
        Admin admin =  adminService.get(name, password);
        if (admin == null) {
            model.addAttribute("msg", "用户名或密码错误");
            return "admin/login";
        }
        session.setAttribute("admin", admin);
        return "redirect:admin_index";
    }

    @RequestMapping("admin_index")
    public String adminIndex() {
        return "admin/index";
    }

    @RequestMapping("admin_top")
    public String adminTop() {
        return "admin/top";
    }

    @RequestMapping("admin_left")
    public String adminLeft() {
        return "admin/left";
    }

    @RequestMapping("admin_right")
    public String adminRight() {
        return "admin/right";
    }

    @RequestMapping("admin_foot")
    public String adminFoot() {
        return "admin/foot";
    }

    @RequestMapping("admin_userManage")
    public String adminUserManage(Model model) {
        List<Customer> customerList = customerService.list();
        model.addAttribute("customerList", customerList);
        return "admin/href/userManage";
    }

    @RequestMapping("admin_classManage")
    public String adminClassManage() {
        return "admin/href/classManage";
    }

    @RequestMapping("admin_smallWareManage")
    public String adminSmallWareManage() {
        return "admin/href/smallWareManage";
    }

    @RequestMapping("admin_userShow")
    public String adminUserShow() {
        return "admin/href/userShow";
    }

    @RequestMapping("admin_goodDetai")
    public String adminGoodDetai() {
        return "admin/href/goodDetai";
    }

    @RequestMapping("admin_announcementManage")
    public String adminAnnouncementManage() {
        return "admin/href/announcementManage";
    }
}
